/*
 * Copyright 2013 Krzysztof Smigielski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.nilcaream.dirstore.cli.command;

import com.nilcaream.dirstore.core.common.ArchiveCreator;
import com.nilcaream.dirstore.core.model.Archive;
import com.nilcaream.dirstore.core.processor.ZipTrimmer;

import javax.inject.Inject;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * TODO
 * <p/>
 * Krzysztof Smigielski 4/20/13 8:33 PM
 */
public class TrimZip extends AbstractTrimCommand {

    @Inject
    private ZipTrimmer trimmer;

    @Override
    public boolean isValid() {
        return super.isValid() && Paths.get(configuration.getInputName()).toFile().isFile();
    }

    @Override
    protected void doTrim(Archive archive, OutputStream outputStream) throws IOException {
        Path input = Paths.get(configuration.getInputName());
        trimmer.createTrimmedZip(input, outputStream, configuration.isQuickMode());
    }

    @Override
    public ArchiveCreator getTrimmer() {
        return trimmer;
    }
}
